package com.chen.controller.user;


import com.chen.pojo.entity.User;
import com.chen.pojo.vo.UserVo;
import com.chen.results.Result;
import com.chen.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 陈子安
 * @since 2023-11-30
 */
@RestController
@RequestMapping("/users/")
@RequiredArgsConstructor
@Api(tags = "用户接口管理")
@Slf4j
public class UserController {

    private final UserService userService;


    // 根据用户id修改用户信息（）
    @ApiOperation("根据用户id修改用户信息")
    @PutMapping("{id}")
    public Result<UserVo> editUserById(@PathVariable("id") Long id, @Validated @RequestBody User user) {
        user.setId(id);
        log.info("修改的用户的为：{}", user);
        UserVo vo = userService.editUserById(user);
        return Result.success(vo);
    }


    // 根据id获取用户
    @GetMapping("{id}")
    @ApiOperation("根据id获取用户信息")
    public Result<UserVo> getUserById(@PathVariable("id") Long id) {
        UserVo vo = userService.getUserById(id);
        log.info("查询的用户id为：{}", id);
        return Result.success(vo);
    }

}
